package cn.bugDance.domain.rebate.service.rule.impl;

import cn.bugDance.domain.rebate.model.entity.BehaviorEntity;
import cn.bugDance.domain.rebate.model.entity.DallyBehaviorRebateEntity;
import cn.bugDance.domain.rebate.model.valobj.DallyBehaviorRebateStateVO;
import cn.bugDance.domain.rebate.repository.IRebateRepository;
import cn.bugDance.domain.rebate.service.rule.AbstractRuleChain;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

@Component("stateRuleChain")
@Slf4j
public class StateRuleChain extends AbstractRuleChain {

    @Resource
    private IRebateRepository rebateRepository;

    @Override
    public List<DallyBehaviorRebateEntity> action(BehaviorEntity behaviorEntity) {
        String behaviorType = behaviorEntity.getBehaviorType();
        List<DallyBehaviorRebateEntity> dallyBehaviorRebateEntities = rebateRepository.queryBehaviorRebateEntities(behaviorType);
        if(dallyBehaviorRebateEntities == null) return null;
        List<DallyBehaviorRebateEntity> dallyBehaviorRebateEntitiesWithoutCLose = new ArrayList<>();
        for(DallyBehaviorRebateEntity dallyBehaviorRebateEntity : dallyBehaviorRebateEntities){
            if(DallyBehaviorRebateStateVO.CLOSE.equals(dallyBehaviorRebateEntity.getState())){
                continue;
            }
            dallyBehaviorRebateEntitiesWithoutCLose.add(dallyBehaviorRebateEntity);
        }
        return dallyBehaviorRebateEntitiesWithoutCLose;
    }
}
